
"use strict";

angular.module('app.configService').controller('SignalCtrl', function($scope,$http,userHttpS){


    // $http.get(baseurls+'admin/return_service').then(function (res) {
    //     if (res) {
           
    //         $scope.serverlist = res.data;
    //     }
    // })      

    var serverInfo = [];
    $scope.getService = function(){
        $('#saveSuccess').hide();
        var serverurl = $("#inputServer").val();
        $http.get(serverurl+"/list_process").success(function(res){
            if(res.ret == 1) {
                $scope.serverlist = res.info;
                $('#failServer').hide();
                $('.configServer').show();
                for(var i=0; i<res.info.length; i++){
                    var info = {};
                    info.name = res.info[i].name;
                    info.ip = res.info[i].ip;
                    info.port = res.info[i].port;
                    info.des = res.info[i].des;
                    info.status = res.info[i].status;
                    serverInfo[i] = info;
                }
              
            }
        }).error(function(){
            $('.configServer').hide();
            $('#failServer').fadeIn();
        })

    } 

    $scope.saveService = function(){

        var server = { info: serverInfo }
        //console.log(serverInfo);
        userHttpS.postAllAdmin('set_service', server).then(function (res) {
            if (res) {
                // console.log(res);
                if(res==1) {
                    $('#saveSuccess').fadeIn();
                }
            }
            else {

                throw new Error("postAllAdmin:res error");
            } 
        })


    }


});